package com.pcbly.web.business.client;

import java.util.HashMap;
import java.util.List;

import com.pcbly.web.bean.client.CustomerBean;
import com.pcbly.web.bean.client.CustomerListBean;
import com.pcbly.web.bean.table.ColumnBean;
import com.pcbly.web.business.BaseServiceImp;
import com.pcbly.web.components.form.AbstractAnalyseCommonDataExt;
import com.pcbly.web.components.form.AnalyseCommonDataExtCreate;
import com.pcbly.web.components.form.AnalyseCommonDataExtEdit;
import com.pcbly.web.components.form.AnalyseCommonDataExtView;
import com.pcbly.web.components.hibernate.support.Page;
import com.pcbly.web.persistence.client.CustomerDao;
import com.pcbly.web.persistence.table.ColumnDao;

public class CustomerServiceImp extends BaseServiceImp<CustomerBean> implements
		CustomerService {

	private CustomerDao customerDao;

	private ColumnDao columnDao;

	public void setColumnDao(ColumnDao columnDao) {
		this.columnDao = columnDao;
	}

	public void setCustomerDao(CustomerDao customerDao) {
		this.customerDao = customerDao;
	}

	public CustomerServiceImp() {
		super();
		// TODO Auto-generated constructor stub
	}

	@Override
	public CustomerBean saveCustomerBean(CustomerBean bean) throws Exception {
		// TODO Auto-generated method stub
		return customerDao.saveCustomerBean(bean);
	}

	@Override
	public Page<CustomerListBean> findCustomerBeanByCond(CustomerBean bean,
			Page<CustomerListBean> page, String orderByName, boolean asc)
			throws Exception {
		// TODO Auto-generated method stub
		return customerDao.findCustomerBeanByCond(bean, page, orderByName, asc);
	}

	@Override
	public CustomerBean updateCustomerBean(CustomerBean bean) throws Exception {
		// TODO Auto-generated method stub
		customerDao.saveObject(bean);
		return bean;
	}

	@Override
	public CustomerBean getCustomerBeanById(String id) throws Exception {
		// TODO Auto-generated method stub
		return customerDao.get(id);
	}

	@Override
	public void deleteCustomerBeanById(String id) throws Exception {
		// TODO Auto-generated method stub
		customerDao.deleteCustomerBeanById(id);
	}

	@Override
	public String findCustomerBeanExtCreate(String tableName) throws Exception {
		// TODO Auto-generated method stub
		List<ColumnBean> columnList = columnDao
				.findColumnBeansByTableName(tableName);
		AbstractAnalyseCommonDataExt common = new AnalyseCommonDataExtCreate();
		common.setColumnList(columnList);
		return common.execute().toString();
	}

	@Override
	public String findCustomerBeanExtEdit(String tableName, String id)
			throws Exception {
		// TODO Auto-generated method stub
		List<HashMap<String, String>> dataList = customerDao
				.findCommnonDataBeanExt(tableName, id);
		List<ColumnBean> columnList = columnDao
				.findColumnBeansByTableName(tableName);
		AbstractAnalyseCommonDataExt common = new AnalyseCommonDataExtEdit();
		common.setDataList(dataList);
		common.setColumnList(columnList);
		return common.execute().toString();
	}

	@Override
	public String findCustomerBeanExtView(String tableName, String id)
			throws Exception {
		// TODO Auto-generated method stub
		List<HashMap<String, String>> dataList = customerDao
				.findCommnonDataBeanExt(tableName, id);
		List<ColumnBean> columnList = columnDao
				.findColumnBeansByTableName(tableName);
		AbstractAnalyseCommonDataExt common = new AnalyseCommonDataExtView();
		common.setDataList(dataList);
		common.setColumnList(columnList);
		return common.execute().toString();
	}

	@Override
	public void saveCustomerBeanExt(String sql) throws Exception {
		// TODO Auto-generated method stub
		customerDao.saveCommnonDataBeanExt(sql);
	}

	@Override
	public boolean getHasCustomerBeanExtData(String tableName, String id)
			throws Exception {
		// TODO Auto-generated method stub
		return customerDao.getHasCommnonDataBeanExt(tableName, id);
	}

	@Override
	public List<CustomerBean> findCustomerBeansByName(String name)
			throws Exception {
		// TODO Auto-generated method stub
		return customerDao.findCustomerBeansByName(name);
	}

}
